package csu.edu.flatprogram.controller.front;

import csu.edu.flatprogram.common.CommonResponse;
import csu.edu.flatprogram.entity.Activity;
import csu.edu.flatprogram.entity.Picture;
import csu.edu.flatprogram.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.PrintWriter;
import java.util.List;

@RestController
@RequestMapping("/flat/activities")
public class ActivityController {

    @Autowired
    private ActivityService activityService;

    //查询所有活动通知信息
    @GetMapping("/select")
    public CommonResponse<List<Activity>> getAllActivities(){
        return activityService.getAllActivities();
    }

    //根据Id查询单个活动信息
    @GetMapping("/select/{id}")
    public CommonResponse<Activity> getActivityById(@PathVariable("id") int activityid){
        return activityService.getActivityById(activityid);
    }
//
//    //新增一条活动通知
//    @GetMapping("/{name}/{start}/{stop}/{place}/{unit}/{details}/add")
//    public CommonResponse<Activity> addActivity(@PathVariable("name") String activityname,
//                                                @PathVariable("start") String starttime,
//                                                @PathVariable("stop") String stoptime,
//                                                @PathVariable("place") String activityplace,
//                                                @PathVariable("unit") String activityunit,
//                                                @PathVariable("details") String activitydetails){
//        return activityService.addActivity(activityname,starttime,stoptime,activityplace,activityunit,activitydetails);
//    }

//    //根据ID更新一条活动信息
//    @GetMapping("/{id}/{name}/{start}/{stop}/{place}/{unit}/{details}/update")
//    public CommonResponse<Activity> updateActivity(@PathVariable("id") int activityid,
//                                                   @PathVariable("name") String activityname,
//                                                   @PathVariable("start") String starttime,
//                                                   @PathVariable("stop") String stoptime,
//                                                   @PathVariable("place") String activityplace,
//                                                   @PathVariable("unit") String activityunit,
//                                                   @PathVariable("details") String activitydetails){
//        return activityService.updateActivity(activityid,activityname,starttime,stoptime,activityplace,activityunit,activitydetails);
//    }

    //通过Id删除活动通知信息
    @DeleteMapping("/delete/{id}")
    public CommonResponse<List<Activity>> deleteActivity(@PathVariable("id") String activityid){
        return activityService.deleteActivity(activityid);
    }

    //添加活动信息
    @PostMapping("/add")
    public CommonResponse<Activity> insertActivity(@RequestBody Activity activity){
        return activityService.insertActivity(activity);
    }

    //修改活动信息
    @PostMapping("/update")
    public CommonResponse<Activity> updateActivity(@RequestBody Activity activity){
        return activityService.updateActivity(activity);
    }

    //单独添加图片
    @PostMapping("picture/add")
    public CommonResponse<Picture> addPicture(@RequestBody Picture picture){
        return activityService.addPicture(picture);
    }

}
